/*
 * Copyright (c) 2011 Team A CS2340. All rights reserved.
 */

package edu.gatech.teama.doctorsoffice.client.presenter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.joda.time.LocalDateTime;
import edu.gatech.teama.doctorsoffice.client.view.AppointmentInfoPanel;
import edu.gatech.teama.doctorsoffice.client.view.MainWindow;
import edu.gatech.teama.doctorsoffice.model.Appointment;

/**
 * The Class AppointmentLookupPresenter. For use with looking up appointments
 * 
 * @author TEAMA
 * @version 1.0
 */
public class AppointmentLookupPresenter { // $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.alwaysOverridetoString.alwaysOverrideToString

	/**
	 * Gets the appointments.
	 *
	 * @param date the date
	 * @return the appointments
	 */
	public List<Appointment> getAppointments(LocalDateTime date) {
		final ServerConnection sc = ServerConnection.getInstance();
		final Map<String, Appointment> appointments =
			sc.getAppointmentsForDate(date.toString("MMddyyyy"));
		if (appointments == null){
			return new ArrayList<Appointment>();
		}
		return new ArrayList<Appointment>(appointments.values());
		
	}
	
	/**
	 * Opens the appointment in the panel.
	 *
	 * @param appointment the appointment
	 */
	public void openAppointment(Appointment appointment) {
		MainWindow.setPanel(new AppointmentInfoPanel(appointment));
	}
}
